﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HTTT.DataAccess;
using HTTT.Utilities;
using HTTT.AD;
using HTTT.DTO;

namespace HTTT.Bussiness
{
    public class HT_RequestBO
    {
        public enum HT_ACTION
        {
            ADD = 1,
            EDIT,
            DELETE,
            RESET


        }

        public IEnumerable<HT_Request> GetAllHT_Request()
        {
            HT_RequestDAO _dao = new HT_RequestDAO();
            return _dao.GetAllHT_Request();
        }
        public HT_Request GetHT_RequestById(Guid id)
        {
            HT_RequestDAO _dao = new HT_RequestDAO();
            return _dao.GetRequest_ID(id);
        }
        public bool InsertRequest(HT_Request inHT_Request)
        {
            HT_RequestDAO _dao = new HT_RequestDAO();
            return _dao.InsertRequest(inHT_Request);
        }


        public ReturnValue<bool> ApproveRequest(Guid TempID, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_RequestBO BO = new HT_RequestBO();
            HT_Request request = BO.GetHT_RequestById(TempID);
            if (request == null)
            {
                return new ReturnValue<bool>(false, "Không tìm thấy yêu cầu!");
            }
            switch (request.Action.ToString())
            {
                case "ADD_USER":
                    return ApproveAddUserRequest(request, authenInfo, approvedBy);
                case "RESET_USER":
                    return ApproveResetUserRequest(request, authenInfo, approvedBy);
                case "DELETE_USER":
                    return ApproveDeleteUserRequest(request, authenInfo, approvedBy);
                case "EDIT_USER":
                    return ApproveEditUserRequest(request, authenInfo, approvedBy);
                case "BLOCK_USER":
                    return ApproveBlockUserRequest(request, authenInfo, approvedBy);
                case "UN_BLOCK_USER":
                    return ApproveUnBlockUserRequest(request, authenInfo, approvedBy);
                case "ADD_GROUP":
                    return ApproveAddGroupRequest(request, authenInfo, approvedBy);
                case "EDIT_GROUP":
                    return ApproveEditGroupRequest(request, authenInfo, approvedBy);
                case "DELETE_GROUP":
                    return ApproveDeleteGroupRequest(request, authenInfo, approvedBy);
                case "EDIT_GROUP_MEMBER":
                    return ApproveEditGroupMemberRequest(request, authenInfo, approvedBy);
                case "ADD_OU":
                    return ApproveAddOURequest(request, authenInfo, approvedBy);
                case "RENAME_OU":
                    return ApproveRenameOURequest(request, authenInfo, approvedBy);
                case "MOVE_OU":
                    return ApproveMoveOURequest(request, authenInfo, approvedBy);
                case "DELETE_OU":
                    return ApproveDeleteOURequest(request, authenInfo, approvedBy);
                default:
                    return new ReturnValue<bool>(false, "Có lỗi xảy ra!");
            }

        }

        private ReturnValue<bool> ApproveMoveOURequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_OUBO OUBO = new HT_OUBO();
            string NewParentPath = OUBO.GetNewParentPathFromMoveString(request.ActionDescription);
            HT_OU OldEditOU = OUBO.GetOldHT_OUFromMoveString(request.ActionDescription);
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.MoveOU(NewParentPath, OldEditOU);

            // 2. Synchonize OU list again
            if (ret.RetValue)
            {
                List<OUDTO> ListOU = manager.GetOUAllList();
                HT_OUBO BO = new HT_OUBO();
                ReturnValue<bool> UpdateResult = BO.SynNewData(ListOU);
                if (!UpdateResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveDeleteOURequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.DeleteOU(request.ActionDescription);

            // 2. Synchonize OU list again
            if (ret.RetValue)
            {
                List<OUDTO> ListOU = manager.GetOUAllList();
                HT_OUBO BO = new HT_OUBO();
                ReturnValue<bool> UpdateResult = BO.SynNewData(ListOU);
                if (!UpdateResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveRenameOURequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_OUBO OUBO = new HT_OUBO();
            string NewName = OUBO.GetNewNameFromRenameString(request.ActionDescription);
            HT_OU OldEditOU = OUBO.GetOldHT_OUFromRenameString(request.ActionDescription);
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.RenameOU(NewName, OldEditOU);

            // 2. Synchonize OU list again to update all OU
            if (ret.RetValue)
            {
                List<OUDTO> ListOU = manager.GetOUAllList();
                HT_OUBO BO = new HT_OUBO();
                ReturnValue<bool> UpdateResult = BO.SynNewData(ListOU);
                if (!UpdateResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }

            // 3. Synchonize all user and group for new OU
            string ouParentPath = OldEditOU.DistinguishedName;
            ouParentPath = ouParentPath.Substring(ouParentPath.IndexOf(',') + 1);
            string NewOUPath = "OU=" + NewName + "," + ouParentPath;

            // Syn for User
            List<HT_User> ListUser = manager.GetUserInOU(NewOUPath);
            HT_UserBO UserBO = new HT_UserBO();
            ReturnValue<bool> SynUser = UserBO.SynNewData(ListUser, OldEditOU.DistinguishedName);
            if (!SynUser.RetValue) return new ReturnValue<bool>(false, "Lỗi đồng bộ lại User");

            // Syn for Group
            List<GroupsDTO> ListGroup = manager.GetGroupListByPath(NewOUPath);
            HT_GroupsBO GroupBO = new HT_GroupsBO();
            ReturnValue<bool> SynGroup = GroupBO.SynNewData(ListGroup, OldEditOU.DistinguishedName);
            if (!SynGroup.RetValue) return new ReturnValue<bool>(false, "Lỗi đồng bộ lại Group");

            // 4. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveAddOURequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_OUBO OUBO = new HT_OUBO();
            HT_OU AddOU = OUBO.GetAddHT_OUFromData(request.ActionDescription);

            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.AddNewOU(AddOU);

            // 2. Update user to database
            if (ret.RetValue)
            {
                HT_OUDAO OUDAO = new HT_OUDAO();
                AddOU.ID = Guid.NewGuid();
                ReturnValue<bool> UpdateResult = OUDAO.InsertHT_OU(AddOU);
                if (!UpdateResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveEditGroupMemberRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            ReturnValue<bool> ret = new ReturnValue<bool>(false, "");
            HT_GroupsBO GroupBO = new HT_GroupsBO();
            List<string> AddList = GroupBO.GetAddListFromEditGroupMemeberData(request.ActionDescription);
            List<string> RemoveList = GroupBO.GetRemoveListFromEditGroupMemeberData(request.ActionDescription);
            HT_Groups Group = GroupBO.GetHT_GroupFromEditGroupMemeberData(request.ActionDescription);
            string CurrentUserList = Group.members;
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);

            if (Group == null)
            {
                return new ReturnValue<bool>(false, "Lỗi: Không tìm thấy thông tin group");
            }

            // Add group
            if (AddList.Count > 0)
            {
                foreach (string username in AddList)
                {
                    if(!string.IsNullOrEmpty(username))
                    {
                        ret = manager.AddUserToGroup(Group.name, username);
                        if (ret.RetValue) CurrentUserList += (username + Constants.MEMBERSPLIT);
                    }
                }
            }

            // Remove group
            if (RemoveList.Count > 0)
            {
                foreach (string username in RemoveList)
                {
                    if (!string.IsNullOrEmpty(username))
                    {
                        ret = manager.RemoveUserFromGroup(Group.name, username);
                        if (ret.RetValue) CurrentUserList.Replace(username + Constants.MEMBERSPLIT, Constants.MEMBERSPLIT.ToString());
                    }
                }
            }

            // 2. Update user to database
            if (ret.RetValue)
            {
                HT_GroupsDAO GroupDAO = new HT_GroupsDAO();
                //Build memberlist string again
                Group.members = CurrentUserList;
                // Update group to database
                bool UpdateResult = GroupDAO.UpdateHT_Groups(Group);
                if (!UpdateResult) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveDeleteGroupRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            // 1. Do delete from AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.DeleteGroupPrincipalBy(request.ActionDescription, authenInfo.Domain);
            //2. Do delete from database
            if (ret.RetValue)
            {
                HT_GroupsBO GroupBO = new HT_GroupsBO();
                ReturnValue<bool> DelResult = GroupBO.DelHT_Groups(request.ActionDescription);
                if (!DelResult.RetValue)
                {
                    return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
                }
            }

            //3. If success then Update this request to Approve
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveEditGroupRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_GroupsBO GroupBO = new HT_GroupsBO();
            HT_Groups UpdateGroup = GroupBO.GetNewHTGroupFromEditUserData(request.ActionDescription);
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.UpdateGroupPrincipalByHT_Groups(UpdateGroup);

            // 2. Update user to database
            if (ret.RetValue)
            {
                HT_GroupsDAO GroupDAO = new HT_GroupsDAO();
                bool UpdateResult = GroupDAO.UpdateHT_Groups(UpdateGroup);
                if (!UpdateResult) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveAddGroupRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_GroupsBO GroupBO = new HT_GroupsBO();
            HT_Groups AddGroup = GroupBO.GetHTGroupFromAddGroupData(request.ActionDescription);
            // 1. Update group to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.AddGroupPrincipalByHT_Groups(AddGroup);

            // 2. Update user to database
            if (ret.RetValue)
            {
                HT_GroupsDAO GroupDAO = new HT_GroupsDAO();
                AddGroup.ID = Guid.NewGuid();
                ReturnValue<bool> UpdateResult = GroupDAO.InsertHT_Groups(AddGroup);
                if (!UpdateResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveUnBlockUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_UserBO UserBO = new HT_UserBO();
            string Username = UserBO.GetUsernameFromBlockRequest(request.ActionDescription);
            bool Status = UserBO.GetStatusFromBlockRequest(request.ActionDescription);
            // 1. Add user to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.SetBlockUserPrincipal(Username + "@" + authenInfo.Domain, Status);

            // 2. Update userControlOption of this user to database
            if (ret.RetValue)
            {
                HT_UserDAO UserDAO = new HT_UserDAO();
                HT_User CurrentUser = UserDAO.GetHT_UserByUsername(Username);
                CurrentUser.userAccountControl = ((long)CurrentUser.userAccountControl ^ (long)Constants.ADS_UF_ACCOUNT_DISABLE);
                UserDAO.UpdateHT_User(CurrentUser);
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveBlockUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedBy)
        {
            HT_UserBO UserBO = new HT_UserBO();
            string Username = UserBO.GetUsernameFromBlockRequest(request.ActionDescription);
            bool Status = UserBO.GetStatusFromBlockRequest(request.ActionDescription);
            // 1. Add user to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.SetBlockUserPrincipal(Username + "@" + authenInfo.Domain, Status);

            // 2. Update userControlOption of this user to database
            if (ret.RetValue)
            {
                HT_UserDAO UserDAO = new HT_UserDAO();
                HT_User CurrentUser = UserDAO.GetHT_UserByUsername(Username);
                long currentAccountOption = (long)CurrentUser.userAccountControl;
                if ((currentAccountOption & Constants.ADS_UF_ACCOUNT_DISABLE) == 0)
                {
                    CurrentUser.userAccountControl += Constants.ADS_UF_ACCOUNT_DISABLE;
                }
                UserDAO.UpdateHT_User(CurrentUser);

            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedBy;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveEditUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedby)
        {
            HT_UserBO UserBO = new HT_UserBO();
            HT_User UpdateUser = UserBO.GetNewHTUserFromEditUserData(request.ActionDescription);
            // 1. Update user to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.UpdateUserPrincipalByHT_User(UpdateUser);

            // 2. Update user to database
            if (ret.RetValue)
            {
                HT_UserDAO UserDAO = new HT_UserDAO();
                bool UpdateResult = UserDAO.UpdateHT_User(UpdateUser);
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedby;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveDeleteUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedby)
        {
            // 1. Delete user from AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.DeleteUserPrincipalByHT_User(request.ActionDescription + "@" + authenInfo.Domain);
            // 2. Delete this user from database
            if (ret.RetValue)
            {
                HT_UserBO UserBO = new HT_UserBO();
                ReturnValue<bool> DelResult = UserBO.DelHT_User(request.ActionDescription);
                if (!DelResult.RetValue) return new ReturnValue<bool>(false, "Lỗi cập nhật cơ sở dữ liệu");
            }

            // 3. If success then Update this request to Approve
            if (ret.RetValue)
            {
                request.Approvedby = approvedby;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private ReturnValue<bool> ApproveResetUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedby)
        {
            // Do reset pwd for user in AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.ResetUserPrincipalByHT_User(request.ActionDescription + "@" + authenInfo.Domain, Constants.DEFAULT_PWD);
            // If success then Update this request to Approve
            if (ret.RetValue)
            {
                request.Approvedby = approvedby;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        private bool UpdateRequestStatus(HT_Request request, HT_REQUESTSTATUS requestStatus)
        {
            request.Status = requestStatus.ToString(); ;
            HT_RequestDAO RequestDAO = new HT_RequestDAO();
            return RequestDAO.UpdateRequest(request);
        }

        private ReturnValue<bool> ApproveAddUserRequest(HT_Request request, HT_AuthenticateInfo authenInfo, string approvedby)
        {
            HT_UserBO UserBO = new HT_UserBO();
            HT_User NewUser = UserBO.BuildHTUserFromAddUserData(request.ActionDescription);
            // 1. Add user to AD
            ADManager manager = new ADManager(
                                authenInfo.Domain
                                , authenInfo.Path
                                , authenInfo.Username
                                , authenInfo.Password);
            ReturnValue<bool> ret = manager.AddUserPrincipalByHT_User(NewUser);

            // 2. Add user to database
            if (ret.RetValue)
            {
                HT_UserDAO UserDAO = new HT_UserDAO();
                NewUser.ID = Guid.NewGuid();
                UserDAO.InsertHT_User(NewUser);
            }
            // 3. Update request status
            if (ret.RetValue)
            {
                request.Approvedby = approvedby;
                request.ApproveDate = DateTime.Now;
                bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.APPROVED);
                if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            }
            return ret;
        }

        public IEnumerable<HT_Request> GetAllHT_RequestByStatus(HT_REQUESTSTATUS hT_REQUESTSTATUS)
        {
            HT_RequestDAO _dao = new HT_RequestDAO();
            return _dao.GetHT_RequestByStatus(hT_REQUESTSTATUS);
        }

        public ReturnValue<bool> DenyRequest(Guid requestId, string denyBy)
        {
            HT_RequestBO BO = new HT_RequestBO();
            HT_Request request = BO.GetHT_RequestById(requestId);
            request.Approvedby = denyBy;
            request.ApproveDate = DateTime.Now;
            bool ChangeStaus = UpdateRequestStatus(request, HT_REQUESTSTATUS.REJECT);
            if (!ChangeStaus) return new ReturnValue<bool>(false, "Lỗi thay đổi trạng thái yêu cầu");
            return new ReturnValue<bool>(ChangeStaus, "");
        }
    }
}
